package com.ets.gui;

import java.awt.BorderLayout;
import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import com.ets.apps.Phantom;

public class ETSFrame extends JFrame
  {
   private static final long serialVersionUID = 1;	
	
   protected static final JScrollPane JScrollPane = null;
	
   public ETSFrame(Phantom ghost)
	 {
	  String cmpny = "Mountain Valley Auto";
      String title = cmpny + " Expense Tracking System (ETS)";
	  setTitle(title);
	  OutputUtils.setFrameSize(this, 75);
	  setUndecorated(false);
	  getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
	  OutputUtils.centerWindow(this);
		
	  setVisible(true);
	  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	  JTabbedPane tabbedPane = new JTabbedPane();
	  tabbedPane.addChangeListener(changeListener);
	    
	  tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
	  String titles[] = {"Vehicles", "Vehicle Edit", "Customers", "Customer Edit", "Vendors", "Vendor Edit",
				         "Users",    "User Edit",    "Reports"};
	  int mnemonic[] = {KeyEvent.VK_V, KeyEvent.VK_H, KeyEvent.VK_C, KeyEvent.VK_S, KeyEvent.VK_E,
		                KeyEvent.VK_N, KeyEvent.VK_U, KeyEvent.VK_D, KeyEvent.VK_R};

	  JPanel panel = null;
	  for (int i = 0, n = titles.length; i < n; i++) 
	    {
		 switch (i)
		   {
		    case 0:
			  panel = new VehiclePanel();
			  break;
		    case 1:
		      panel = new VehicleEditPanel();
			  break;
		    case 2:
			  panel = new CustomerPanel();
			  break;
		    case 3:
			  panel = new CustomerEditPanel();
			  break;
		    case 4:
		      panel = new VendorPanel();
			  break;
		    case 5:
		      panel = new VendorEditPanel();
			  break;
		    case 6:
		      panel = new UserPanel();
			  break;
		    case 7:
			  panel = new UserEditPanel();
		      break;
		    case 8:
			  panel = new ReportsPanel();
			  break;
			default:
			  i = 0;
			  panel = new VehiclePanel();
			  break;
		   }
		  
		  
		  
		  
		 add(tabbedPane, titles[i], mnemonic[i], panel);
	     System.out.println("mnemonic[i]: " + mnemonic[i]);
	    }

	  add(tabbedPane, BorderLayout.CENTER);
	 }
   
   ChangeListener changeListener = new ChangeListener() 
     {
      public void stateChanged(ChangeEvent changeEvent) 
        {
         JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent.getSource();
         System.out.println("index = sourceTabbedPane.getSelectedIndex()");
        }
     };
 	
   static void add (JTabbedPane tabbedPane, String label, int mnemonic, JPanel panel) 
     {
      int count = tabbedPane.getTabCount();

      JButton button = new JButton(label); //This adds the label to the center of the screen
      //tabbedPane.addTab(label, button);
    	
      tabbedPane.addTab(label, panel);
    	    	
      tabbedPane.setMnemonicAt(count, mnemonic);  // does not effect menu that much
     }
  }
